#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
int main() {  
    // 打开一张本地图片  
    cv::Mat image = cv::imread("//home//xwz//作业//lesson_4//2.jpg");  
    if (image.empty()) {  
        std::cout << "Could not open or find the image" << std::endl;  
        return -1;  
    }  
  
    // 显示原图  
    cv::imshow("Original Image", image);  
  
    // 灰度化  
    cv::Mat grayImage;  
    cv::cvtColor(image, grayImage, cv::COLOR_BGR2GRAY);  
    cv::imshow("Gray Image", grayImage);  
  
    // 二值化  
    cv::Mat binaryImage;  
    cv::threshold(grayImage, binaryImage, 100, 255, cv::THRESH_BINARY);  
    cv::imshow("Binary Image", binaryImage);  
  
    // 打开摄像头  
    cv::VideoCapture cap(0);  
    if (!cap.isOpened()) {  
        std::cout << "Error opening video stream" << std::endl;  
        return -1;  
    }  
  
    cv::Mat cameraFrame;  
    while (true) {  
        cap >> cameraFrame;  
        if (cameraFrame.empty()) break;  
  
        cv::imshow("Camera", cameraFrame);  
  
        if (cv::waitKey(10) == 27) break; // 等待ESC退出  
    }  
  
    cap.release();  
    cv::destroyAllWindows();  
    return 0;  
}
